//
//  FindTopCollectionViewCell.m
//  TasteEnjoy
//
//  Created by XuRui on 16/4/28.
//  Copyright © 2016年 XuRui. All rights reserved.
//

#import "FindTopCollectionViewCell.h"

@interface FindTopCollectionViewCell ()

@property (nonatomic,retain)BaseImageView *imgPhoto;
@property (nonatomic,retain)BaseLabel *labelGroup;

@end

@implementation FindTopCollectionViewCell

#pragma mark - ------------ 内存管理 ---------------
- (void)dealloc
{
    [_imgPhoto release];
    [_labelGroup release];
    [_model release];
    
    [super dealloc];
}


#pragma mark - ------------ 初始化 ---------------
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self creatSub];
    }
    return self;
}

#pragma mark - ------------ 创建子视图 ---------------
- (void)creatSub
{
    
    
    self.labelGroup = [[BaseLabel alloc]init];
    [self.contentView addSubview:_labelGroup];
    _labelGroup.font = [UIFont systemFontOfSize:13];
    _labelGroup.textAlignment = NSTextAlignmentCenter;
    
    self.imgPhoto = [[BaseImageView alloc]init];
    [self.contentView addSubview:_imgPhoto];
/** 夜间 */
    _labelGroup.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor lightGrayColor]);
    
//    _imgPhoto.backgroundColor = [UIColor orangeColor];
//    _labelGroup.backgroundColor = [UIColor redColor];
    [_imgPhoto release];
    [_labelGroup release];
    
}

#pragma mark - ------------ 重新布局 ---------------
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    
    _imgPhoto.translatesAutoresizingMaskIntoConstraints = NO;
    _labelGroup.translatesAutoresizingMaskIntoConstraints = NO;
    
    [_imgPhoto mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(self.contentView).offset(0);
        
        make.right.mas_equalTo(self.contentView).offset(0);
        make.height.mas_equalTo(100);
    }];
    
    [_labelGroup mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_imgPhoto.mas_bottom).offset(0);
        make.left.mas_equalTo(self.contentView).offset(5);
        make.right.mas_equalTo(self.contentView).offset(-5);
        make.height.mas_equalTo(20);
    }];

    
}

#pragma mark - ------------ 赋值 ---------------
- (void)setModel:(FindModel *)model
{
    
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [_imgPhoto sd_setImageWithURL:[NSURL URLWithString:model.icon_url] placeholderImage:PLACEHOLDER];
    
    _labelGroup.text = model.name;
 
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
